package com.teacher.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.teacher.common.CommonResult;
import com.teacher.mapper.HealthDeviceMapper;
import com.teacher.pojo.entity.HealthData;
import com.teacher.mapper.HealthDataMapper;
import com.teacher.service.IHealthDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiangzhuohang
 * @since 2025-04-12
 */
@Service
public class HealthDataServiceImpl extends ServiceImpl<HealthDataMapper, HealthData> implements IHealthDataService {

    @Autowired
    private HealthDataMapper healthDataMapper;

    @Override
    public CommonResult getHealthData(String number) {
        List<HealthData> healthData = healthDataMapper.selectList(new QueryWrapper<HealthData>().lambda().eq(HealthData::getDeviceNumber, number));

        return CommonResult.success(healthData);
    }

    @Override
    public CommonResult addHealthData(String number, Integer type, Integer data) {
        HealthData healthData = new HealthData();
        healthData.setDeviceNumber(number);
        healthData.setType(type);
        healthData.setValue(data);

        int insert = healthDataMapper.insert(healthData);
        if (insert<1) {
            return CommonResult.failed("新增失败");
        }
        return CommonResult.success("新增成功");
    }
}
